import request from '../tools/index.js'

// axios.get(url, {
//   params:{
//     要发送的数据,键值对的形式
//   }
// }).then(data=>{
//   成功
// })

// axios.post(url,{
//   要发送的数据,键值对的形式
// }).then(data=>{
//   成功
// })

export function getBanner () {
  return request.get('/banner')
}

export function getNav () {
  return request.get('/pro/column')
}

export function getPro (params) {
  return request.get('/pro/page', { params })
}

export function getDetail (params) {
  return request.get('/pro/one', { params })
}

export function sendCode (params) {
  return request.get('/user/sendMsg', { params })
}

export function register (params) {
  return request.post('/user/register', params)
}

export function login (params) {
  return request.get('/user/login', { params })
}

export function getCart (params) {
  return request.get('/cart', { params })
}

export function addCart (params) {
  return request.post('/cart/add', params)
}

export function updateCartNum (params) {
  return request.post('/cart/updateNum', params)
}

export function delCart (params) {
  return request.post('/cart/del', params)
}

export function updateFlag (params) {
  return request.post('/cart/updateFlag', params)
}

export function updateAllFlag (params) {
  return request.post('/cart/updateAllFlag', params)
}

export function addOrder (params) {
  return request.post('/order/add', params)
}

export function getOrder (params) {
  return request.get('/order', { params })
}

export function pay (params) {
  return request.post('/order/pay', params)
}

export function getOrderDetail (params) {
  return request.get('/order/detail', { params })
}

export function getAddress (params) {
  // 这里在使用promise+延时器,模拟真实的后端请求数据的操作
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve([{
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true
      }])
    }, 10)
  })
}

export function getCoupon (params) {
  // 这里在使用promise+延时器,模拟真实的后端请求数据的操作
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        available: 1,
        condition: '无使用门槛\n最多优惠12元',
        reason: '',
        value: 250,
        name: '优惠券名称',
        startAt: 1489104000,
        endAt: 1514592000,
        valueDesc: '2.5',
        unitDesc: '元'
      })
    }, 10)
  })
}

export function getSearch (params) {
  return request.get('/search', { params })
}

export function addSearch (params) {
  return request.post('/search/add', params)
}

export function delSearch (params) {
  return request.post('/search/del', params)
}

export function searchPro (params) {
  return request.get('/pro/search', { params })
}
